package View;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

import javax.imageio.ImageIO;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JToggleButton;
import javax.swing.Timer;

import Controler.Controleur;
import Model.LED;
import Model.Manette;
import Model.TrainAterrissage;


public class Display {
	JFrame frame=new JFrame("Train Aterrissage");
	JLabel result=new JLabel("Result:");
	JLabel execution=new JLabel("Execution time:");
	JProgressBar progress1=new JProgressBar();
	JProgressBar progress2=new JProgressBar();
	JProgressBar progress3=new JProgressBar();
	JButton boutonManette=new JButton();
	JPanel LEDs=new JPanel(new BorderLayout());
	JLabel imageLEDs= new JLabel();
	JPanel aterrissage=new JPanel(new BorderLayout());
	JLabel aterrissageImage= new JLabel();
	JPanel aterrissage2=new JPanel(new BorderLayout());
	JLabel aterrissageImage2= new JLabel();
	JPanel aterrissage3=new JPanel(new BorderLayout());
	JLabel aterrissageImage3= new JLabel();
	
	ImageIcon buttonUp = null;
	ImageIcon buttonDown = null;
	
	ImageIcon LEDrouge = null;
	ImageIcon LEDvert = null;
	ImageIcon LEDorange = null;
	ImageIcon LEDeteinte = null;
	
	ImageIcon ouvert = null;
	ImageIcon transitionup = null;
	ImageIcon transitiondown = null;
	ImageIcon ferme = null;
	
	
	
	//long start,stop;
	
	Controleur controleur;
	
	
	public Display(final Controleur controleur){
		
		this.controleur = controleur;
		
		boutonManette.setBorder(BorderFactory.createEmptyBorder());
		boutonManette.setContentAreaFilled(false);
		try {
			buttonUp = new ImageIcon(ImageIO.read(new File("res/images/up.png")));
			buttonDown = new ImageIcon(ImageIO.read(new File("res/images/down.png")));
			LEDrouge = new ImageIcon(ImageIO.read(new File("res/images/rouge.png")));
			LEDvert = new ImageIcon(ImageIO.read(new File("res/images/vert.png")));
			LEDorange = new ImageIcon(ImageIO.read(new File("res/images/orange.png")));
			LEDeteinte = new ImageIcon(ImageIO.read(new File("res/images/eteinte.png")));
			ouvert = new ImageIcon(ImageIO.read(new File("res/images/ouvert.png")));
			ferme = new ImageIcon(ImageIO.read(new File("res/images/ferme.png")));
			transitionup = new ImageIcon(ImageIO.read(new File("res/images/transition.png")));
			transitiondown = new ImageIcon(ImageIO.read(new File("res/images/transitiondown.png")));
		} catch (IOException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		boutonManette = new JButton(buttonUp);
		frame.add(boutonManette);
		

		imageLEDs = new JLabel("", LEDeteinte, JLabel.CENTER);
		LEDs.add( imageLEDs, BorderLayout.CENTER );
		frame.add(LEDs);
		
		aterrissageImage = new JLabel("", ferme, JLabel.CENTER);
		aterrissage.add( aterrissageImage, BorderLayout.CENTER );
		aterrissage.add( progress1, BorderLayout.PAGE_END );
		frame.add(aterrissage);
		aterrissageImage2 = new JLabel("", ferme, JLabel.CENTER);
		aterrissage2.add( aterrissageImage2, BorderLayout.CENTER );
		aterrissage2.add( progress2, BorderLayout.PAGE_END );
		frame.add(aterrissage2);
		aterrissageImage3 = new JLabel("", ferme, JLabel.CENTER);
		aterrissage3.add( aterrissageImage3, BorderLayout.CENTER );
		aterrissage3.add( progress3, BorderLayout.PAGE_END );
		frame.add(aterrissage3);
		
		
		boutonManette.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				
				controleur.boutonManetteActioned();
			}
		});
	

	
		frame.setLayout(new FlowLayout());
		frame.setResizable(false);
		frame.setSize(400,600);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}
	
	public void transitionUp(){
		boutonManette.setIcon(buttonUp);

		aterrissageImage.setIcon(transitionup);
		aterrissageImage2.setIcon(transitionup);
		aterrissageImage3.setIcon(transitionup);
	}
	
	public void transitionDown(){
		boutonManette.setIcon(buttonDown);

		aterrissageImage.setIcon(transitiondown);
		aterrissageImage2.setIcon(transitiondown);
		aterrissageImage3.setIcon(transitiondown);
	}
	
	public void imageLEDs_setIcon_LEDorange(){
		imageLEDs.setIcon(LEDorange);
	}
	
	public void imageLEDs_setIcon_LEDeteinte(){
		imageLEDs.setIcon(LEDeteinte);
	}
	
	public void imageLEDs_setIcon_LEDvert(){
		imageLEDs.setIcon(LEDvert);
	}
	
	public void aterrissageImage_setIcon_ouvert(){
		aterrissageImage.setIcon(ouvert);
	}
	public void aterrissageImage_setIcon_ferme(){
		aterrissageImage.setIcon(ferme);
	}

	public void aterrissageImage2_setIcon_ouvert(){
		aterrissageImage2.setIcon(ouvert);
	}
	public void aterrissageImage2_setIcon_ferme(){
		aterrissageImage2.setIcon(ferme);
	}

	public void aterrissageImage3_setIcon_ouvert(){
		aterrissageImage3.setIcon(ouvert);
	}
	public void aterrissageImage3_setIcon_ferme(){
		aterrissageImage3.setIcon(ferme);
	}

		

}




